<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../css/layui.css">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
</head>
<body>

<div style="margin-top: 1%;">
        <div class="layui-inline" style="margin-left: 150px;">
            <div class="layui-input-inline">
                <input type="text" id="groupname"   style="width: 220px;"  placeholder="请输入分组名称"autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-inline">
            <button type="button" class="layui-btn" id="btnSearch">搜索</button>
        </div>
</div>
<div style="padding-left: 50px;">
    <caption style="margin-left: 40px;"><span >
                <button type="button" class="btn btn-primary layui-btn"  onclick="method5('tableExcel')">
                    <span class="glyphicon glyphicon-folder-open">导出Excel</span>
                </button>
            </span>
    </caption>
</div>
<table class="layui-table" id="groupdata" lay-filter="groupdata">

</table>
</body>
<script type="text/html" id="tol">
    <div>
        <div style="float:left;">分组列表</div>
        <div style="float:right;margin-right: 50px">共有数据：<span id="count"></span>条</div>
    </div>

</script>

<script type="text/html" id="caozuo">
    <ul  class="kit-menu-child layui-anim layui-anim-upbit">
        <a class="layui-btn layui-btn-xs" lay-event="edit">使用</a>
    </ul>


</script>

</html>
<script type="text/javascript">
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table = layui.table
            , layer = layui.layer
            , util = layui.util;

        var stationid=localStorage.getItem('groupStationId');
        var s=layui.data("s");
        var terminalid=s.terminal.terminal_id;

        table.render({
            elem: '#groupdata'
            ,  id: "t"
            ,  toolbar:"#tol"
            ,url:'/admin/group/terminalGroupQiYong?groupStationId='+stationid
            , method: 'GET'
            ,cols: [[
                {field:'groupId', title: '分组编号',
                    align: "center"}
                ,{field:'groupName', title: '分组名称',
                    align: "center"}
               ,{
                    title:'操作',
                    align:'center',
                    toolbar:'#caozuo',
                }
            ]],
            page: true,
            done: function(res, curr, count){
                $("#count").html(count);
            }
        });



        table.on('tool(groupdata)',function(obj){
            var getdata=obj.data; //获取当前行数据
            var layEvent=obj.event; //获取lay-event对应的值,(也可以是表头的event参数对应的值)
            var tr=obj.tr; //获取当前行tr的DOM对象(如果有的话)
            switch(layEvent){
                case "edit":
                    $.ajax({
                        url:"/admin/terminal/updateTerminalGroup",
                        method: 'PUT',
                        data:{
                            terminalId:terminalid,
                            terminalGroup:getdata.groupId
                        },
                        success:function (data) {
                            if (data.code==200){
                                layer.msg("使用成功", {
                                    icon: 6,//成功的表情
                                    time: 2000 //1秒关闭（如果不配置，默认是3秒）
                                    ,end:function () {
                                        localStorage.setItem("ifclone","1");
                                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                        //layer.msg(index);
                                        parent.layer.close(index); //再执行关闭
                                        parent.location.reload();
                                    }
                                });
                            }else{
                                layer.msg("使用失败", {icon: 5,time: 1000});//失败的表情
                                return;
                            }
                        }

                    })


                    break;
            }
        });


        $("#btnSearch").click(function(){
            table.reload("t",{
                where:{
                    groupName:$("#groupname").val()
                },
                page:{
                    curr:1
                }
            });
        });


</script>
